package eu.reply.android.flashm.common;

/**
 * An instance of this class is created as the result of a {@link HttpConnection}
 * or {@link HttpAsyncConnection}. It is not intended to be instantiated manually
 * 
 * @author Cuauhtemoc Delgado
 *
 */
public class HttpError {
	int statusCode;
	String contentType;
	String contentEncoding;
	String content;
	String location;
	
	/**
	 * Constructor to be used within a {@link HttpConnection} or {@link HttpAsyncConnection}
	 * to represent the result of the connection. It is not indented to be used outside the
	 * instances of HTTP connections.
	 * 
	 * @param statusCode The HTTP status code received
	 * @param content The content of the HTTP message
	 * @param contentType The MIME type associated to {@code content}
	 * @param contentEncoding The encoding associated to {@code content}
	 */
	protected HttpError(int statusCode,String content,String contentType,String contentEncoding){
		this.statusCode=statusCode;
		this.content=content;
		this.contentType = contentType;
		this.contentEncoding = contentEncoding;
	}

	/**
	 * Get the MIME type associated to the content in this error
	 * @return The MIME type of the content or null if there is no content-type associated
	 * @see #getContent()
	 */
	public String getContentType() {
		return contentType;
	}

	/**
	 * Returns the content encoding type associated to the response 
	 * or null if there was no encoding specified.
	 * 
	 * @return the encoding of the content (i.e. UTF-8)
	 */
	public String getContentEncoding() {
		return contentEncoding;
	}

	/**
	 * Return the content received from the error stream of the Http Connection.
	 * The content can be converted to a string like this:
	 * 
	 * <i>String JSONString = new String(httpResp.getContent(), httpResp.getContentEncoding())</i>
	 * 		
	 * @return The content of http response
	 */
	public String getContent() {
		return content;
	}

	/**
	 * Get the status of the HTTP response (e.g 400)
	 * @return the status code or -1 if no valid response was received
	 */
	public int getStatusCode() {
		return statusCode;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}
}
